Yes.
Integer Primitive Data Types | ||
---|---|---|
Type | Size | Range |
byte | 8 bits | -128 to +127 |
short | 16 bits | -32,768 to +32,767 |
int | 32 bits | (about)-2 billion to +2 billion |
long | 64 bits | (about)-10E18 to +10E18 |
Numbers are so important in Java that 6 of the 8 primitive data types are numeric types.
There are both integer and floating point primitive types. Integer types have no fractional part; floating point types have a fractional part. On paper, integers have no decimal point, and floating point types do. But in main memory, there are no decimal points: even floating point values are represented with bit patterns. There is a fundamental difference between the method used to represent integers and the method used to represent floating point numbers.
Floating Point Primitive Data Types | ||
---|---|---|
Type | Size | Range |
float | 32 bits | -3.4E+38 to +3.4E+38 |
double | 64 bits | -1.7E+308 to 1.7E+308 |
Each primitive type uses a fixed number of bits.
This means that if you are using a particular data type
then the same number of bits will be used no matter what value is
represented.
For example,
all values represented using the short
data type
will use 16 bits.
The value zero (as a short
) will use 16 bits and
the value thirty thousand will use 16 bits.
All values represented using the long
data type
will use 64 bits.
The value zero (as a long
) will use 64 bits,
the value thirty thousand will use 64 bits,
and the value eight trillion will use 64 bits.
Values that are large in magnitude (negative or positive) need more bits to be represented. This is simular to writing out numbers on paper: large numbers need more digits. If a value needs more bits than a particular data type uses, then it cannot be represented using that data type.